package spark_core

import org.apache.spark.sql.SparkSession
//import spark.implicits._

object Test1 {
  def main(args: Array[String]): Unit = {

    //sparkStreaming实例
    val spark=SparkSession.builder().appName("dataFrameDemo").getOrCreate()
    import spark.implicits._
   //准备数据源
    val lines=spark.readStream.format("socket")
      .option("host","192.168.80.133")
      .option("port",9999)
      .load()
    val wordCount=lines.as[String]
      .flatMap(_.split(" "))
      .groupBy(col1="value")
      .count()
    //输出结果集
    val query=wordCount.writeStream.format("console")
      .outputMode("complete")
      .start()
    query.awaitTermination()



  }

}
